package com.ztom.v2;

/**
 * @author ZhangTao
 */
public class Code04MoveZeroes {

    public void moveZeroes(int[] nums) {
        if (nums.length == 1) {
            return;
        }
        int slow = 0;
        // 快指针把非 0 全部挪到慢指针处
        for (int fast = 0; fast < nums.length; fast++) {
            if (nums[fast] != 0) {
                nums[slow++] = nums[fast];
            }
        }
        // 剩下全部填 0
        while (slow < nums.length) {
            nums[slow++] = 0;
        }
    }
}
